
/****************************************************************************/

__attribute__((noreturn))
static void idleThread(void)
{
	// This is the idle task.  It runs in this loop whenever no other 
	// processes need the CPU.  This should be run at the absolute lowest
	// possible priority so that it will not be run unless there is absolutely
	// nothing else in the other queues that is ready.

	while(1)
	{
		kernelProcessorPause();
	}
}

/****************************************************************************/

static int spawnIdleThread(void)
{
	// This function will create the idle thread at initialization time.
	// Returns 0 on success, negative otherwise.

	int status = 0;
	int idleProcId = 0;

	// The idle thread needs to be a child of the kernel
	idleProcId = kernelMultitaskerSpawnKernelThread(idleThread, "idle thread", 0, NULL);
	if (idleProcId < 0)
		return (idleProcId);

	ACQUIRE_LOCK_PROCESS_QUEUE();
	idleProc = getProcessById(idleProcId);
	RELEASE_LOCK_PROCESS_QUEUE();
	if (idleProc == NULL)
		return (status = ERR_NOSUCHPROCESS);

	// Set it to the lowest priority
	status = kernelMultitaskerSetProcessPriority(idleProcId, (PRIORITY_LEVELS - 1));
	if (status < 0)
		// There's no reason we should have to fail here, but make a warning
		kernelError(kernel_warn, "The multitasker was unable to lower the priority of the idle thread");

	// Return success
	return (status = 0);
}

/****************************************************************************/
